package cn.k.domain;

import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Getter
@Setter
public class SystemMenu {

    public static final int MENU_TYPE_DIRECTORY=0; //目录
    public static final int READ_TYPE_MENU=1; //菜单

    public static final int STATUS_TYPE_UNABLE=0; //禁用
    public static final int STATUS_TYPE_ENABLE =1; //启用


    /** 菜单id*/
    private Long id;
    /** 菜单名字*/
    private String name;
    /** 缩写*/
    private String sn;
    /** 菜单url*/
    private String menuUrl;
    /** 菜单图标*/
    private String menuIco;
    /** 菜单状态*/
    private Integer menuStatus;
    /** 菜单类型*/
    private Integer menuType;

    /** 创建时间*/
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date createTime;
    /** 父类id*/
    private Integer parentId;
    /** 父类名字*/
    private String parentName;
    /** 权限表达式*/
    private String menuExpression;

    List<SystemMenu> children =new ArrayList<>();


    public String getMenuTypeDisplay(){
        switch (menuType){
            case MENU_TYPE_DIRECTORY :return "目录";
            case READ_TYPE_MENU :return "菜单";
            default: return "未知";
        }
    }

    public String getMenuStatusDisplay(){
        switch (menuStatus){
            case STATUS_TYPE_UNABLE :return "禁用";
            case STATUS_TYPE_ENABLE :return "启用";
            default: return "未知";
        }
    }


    public String toJson(){
        HashMap<String, Object> map = new HashMap<>();
        map.put("id",id);
        map.put("name",name);
        map.put("menuUrl",menuUrl);
        map.put("parentId",parentId);
        map.put("menuType",menuType);
        return JSON.toJSONString(map);
    }


}